package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.pojo.User;
import com.itheima.service.UserServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

// 控制类
@RestController
public class UserOperator {


    @Autowired
    UserServiceImp userService;


    @RequestMapping("/operatorUser")
    public Result operatorUser() {
        // 1. 解析xml文件, 获取数据
        // 获取xml文件的相对路径
//        String path = UserOperator.class.getClassLoader().getResource("user.xml").getPath();
//        List<User> userList = XmlParserUtils.parse(path);
//
//        // 2. 遍历集合,获取所有的user对象, 对省份和城市操作
//        for (User user : userList) {
//            user.getAddress().setProvince(user.getAddress().getProvince() + " 省/市");
//            user.getAddress().setCity(user.getAddress().getCity() + " 区/县");
//
//        }
//        UserService  userService = new UserService();  //解耦

        List<User> userServiceList = userService.getUserServiceList();
        // 封装返回数据
        Result result = Result.success(userServiceList);
        System.out.println(result);
        return result;
    }

}
